package com.lotto.manager.trading.core;

import java.util.concurrent.LinkedBlockingQueue;

import org.apache.log4j.Logger;

import com.lotto.manager.admin.entity.db.Bet;
import com.lotto.manager.common.utils.SpringUtil;
import com.lotto.manager.trading.dto.BetDto;
import com.lotto.manager.trading.service.IBettingService;


public class BettingQueue implements Runnable{
	// 日志
	protected Logger log = Logger.getLogger(BettingQueue.class);
	
	private IBettingService bettingService;
	
	private LinkedBlockingQueue<Bet> queue = new LinkedBlockingQueue<Bet>();;
	public void run() {
		bettingService = (IBettingService)SpringUtil.getBean("bettingService");
		while (true) {
			try {
				/**
				 * 优化可能，用线程池执行。 用lock做资源同步锁
				 */
				Bet bet = queue.take();
				bettingService.betting(bet);
			} catch (InterruptedException e) {
				log.error("注单消费线程出错：",e);
			}
		}
	}

	public void addQueue(Bet bet){
		queue.add(bet);
	}
	
	public void setBettingService(IBettingService bettingService){
		this.bettingService = bettingService;
	}
}
